/**
 * 维保管理API接口
 */

import { requestClient } from '#/api/request';

/**
 * 申请类型枚举
 */
export enum RequestType {
  MAINTENANCE = '保养',
  REPAIR = '维修',
}

/**
 * 审批状态枚举
 */
export enum ApprovalStatus {
  APPROVED = '已批准',
  PENDING = '待审批',
  REJECTED = '已驳回',
}

/**
 * 维保申请接口
 */
export interface MaintenanceRequest {
  requestId: number;
  vehicleId: number;
  driverId: number;
  licensePlate: string;
  driverName: string;
  requestType: RequestType;
  description: string;
  imageUrls?: string[];
  requestTime: string;
  approvalStatus: ApprovalStatus;
  approverId?: number;
  approvalNotes?: string;
  approvalTime?: string;
  cost?: number;
}

/**
 * 维保申请查询参数
 */
export interface MaintenanceRequestQueryParams {
  licensePlate?: string;
  driverName?: string;
  requestType?: RequestType;
  approvalStatus?: ApprovalStatus;
  page?: number;
  pageSize?: number;
}

/**
 * 维保申请分页响应
 */
export interface MaintenanceRequestPageResponse {
  items: MaintenanceRequest[];
  total: number;
  page: number;
  pageSize: number;
}

/**
 * 审批请求参数
 */
export interface ApprovalRequest {
  requestId: number;
  approvalStatus: ApprovalStatus;
  approvalNotes?: string;
}

/**
 * 审批响应接口
 */
export interface ApprovalResponse {
  success: boolean;
  message?: string;
}

/**
 * 获取待审批列表
 */
export async function getPendingRequestsApi(
  params: MaintenanceRequestQueryParams,
): Promise<MaintenanceRequestPageResponse> {
  return requestClient.get<MaintenanceRequestPageResponse>(
    '/api/maintenance/pending',
    { params },
  );
}

/**
 * 获取申请详情
 */
export async function getRequestDetailApi(
  requestId: number,
): Promise<MaintenanceRequest> {
  return requestClient.get<MaintenanceRequest>(`/api/maintenance/${requestId}`);
}

/**
 * 审批申请
 */
export async function approveRequestApi(
  data: ApprovalRequest,
): Promise<ApprovalResponse> {
  return requestClient.post<ApprovalResponse>('/api/maintenance/approve', data);
}

/**
 * 驳回申请
 */
export async function rejectRequestApi(
  data: ApprovalRequest,
): Promise<ApprovalResponse> {
  return requestClient.post<ApprovalResponse>('/api/maintenance/reject', data);
}
